from config.all_paths import allure_report_prometheusData
from notify.send_feishu import parse_prometheus_data,generate_message_content, push_message
from utils.file_handling.ini_handling import LoadIni
from utils.others_tool.other_tool import get_opt
import sys
from utils.jenkins_tool.operation_jenkins import OperationJenkins


def main():
    # 获取命令行参数
    t_opt = get_opt(sys.argv[1:])
    jobname = t_opt.get('job')
    push_type = t_opt.get('type')

    # 获取推送的webhook地址
    webhook_test = LoadIni("notify_variable.ini").getSection('feishu').get('webhook_test')
    webhook_pro = LoadIni("notify_variable.ini").getSection('feishu').get('webhook_pro')

    # 获取jenkins配置
    jenkins_config = LoadIni("jenkins.ini").getSection('jenkins')

    # 构造推送的报告，并推送
    content = parse_prometheus_data(allure_report_prometheusData)
    description = OperationJenkins(jobname, jenkins_config).get_job_description()
    report_url = OperationJenkins(jobname, jenkins_config).get_report_url()
    message_content = generate_message_content(content, description,report_url)

    if push_type == 'test':
        push_message(webhook_test, message_content)
    elif push_type == 'pro':
        push_message(webhook_pro, message_content)
    else:
        print("请输入正确的推送环境参数")



if __name__ == '__main__':
    main()
    # python run_send_message.py --type=test --job=jenkins_jobname
